function deleteQuestion(number){
    $.ajax({
        method: 'POST',
        url: '/admin/delete_question/'+number,
        dataType: 'json',  
        contentType: 'application/json;charset=utf8',
        success: function(data) {  
            alert(data)
        }
    });
}

// function addQuestion() {
//     const formData = {
//         number: document.getElementById('questionNumber').value,
//         title: document.getElementById('title').value,
//         star: document.getElementById('star').value,
//         desc: document.getElementById('desc').value,
//         header: document.getElementById('header').value,
//         tail: document.getElementById('tail').value,
//         test_input: document.getElementById('testInput').value,
//         cpu_commit: document.getElementById('cpuLimit').value,
//         mem_commit: document.getElementById('memLimit').value
//     };

//     fetch('/admin/add_question', {
//         method: 'POST',
//         headers: { 'Content-Type': 'application/json' },
//         body: JSON.stringify(formData)
//     })
//     .then(response => response.text())
//     .then(data => {
//         alert(data);  // 显示添加成功或失败
//         location.reload();  // 刷新页面，显示最新题目列表
//     })
//     .catch(error => console.error('添加题目失败:', error));
// }


///1
function submitQuestionForm() {
    const questionData = {
        number: document.getElementById('questionNumber').value,
        title: document.getElementById('title').value,
        star: document.getElementById('star').value,
        desc: document.getElementById('desc').value,
        header: document.getElementById('header').value,
        tail: document.getElementById('tail').value,
        test_input: document.getElementById('testInput').value,
        cpu_commit: Number(document.getElementById('cpuLimit').value) || 3,
        mem_commit: Number(document.getElementById('memLimit').value) || 50000
    };

    $.ajax({
        method: 'POST',
        url: '/admin/save_question',
        contentType: 'application/json;charset=utf-8',
        data: JSON.stringify(questionData),
        success: function(response) {
            alert(response);
            location.reload(); // 刷新列表
        },
        error: function(xhr) {
            alert('保存失败: ' + xhr.responseText);
        }
    });
}
